package AMT;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Scanner;

public class mainclass {
    public static void main(String[] args) {
        //这是一个key值为int类型，value值为String类型的map集合
        //map的特点在于键值对，就是一个key对应一个value
        HashMap<String,User> map = new HashMap<>();
        User zhangsan = new User("张三","123",100);
        map.put("123",zhangsan);
        while (true){
            //登录界面
            Scanner scanner = new Scanner(System.in);
            System.out.println("-----欢迎来到中国农业银行-----");
            System.out.println("----请输入卡号----");
            String id = scanner.nextLine();
            System.out.println("----请输入密码----");
            String pwd = scanner.nextLine();

            if (UserDao.login(id,pwd,map)) {
                System.out.println("登录成功!");

                while (true){
                    System.out.println("-----欢迎来到中国农业银行！-----");
                    System.out.println("1.修改密码");
                    System.out.println("2.存钱");
                    System.out.println("3.取钱");
                    System.out.println("4.查询余额");
                    System.out.println("5.退出");
                    System.out.println("6.查询交易记录");

                    Scanner scanner1 = new Scanner(System.in);
                    String ling = scanner1.nextLine();
                    switch (ling){
                        case "1":
                            Scanner scanner2 = new Scanner(System.in);
                            System.out.println("请输入新密码");
                            String pwd1 = scanner2.nextLine();
                            System.out.println("请再次输入新密码");
                            String pwd2 = scanner2.nextLine();
                            if(pwd1.equals(pwd2)){
                                UserDao.changePassword(id,pwd1,map);
                                System.out.println("修改密码成功");
                            }
                            break;
                        case "2":
                            Scanner scanner3 = new Scanner(System.in);
                            System.out.println("请输入要存的金额");
                            double money = scanner3.nextDouble();
                            UserDao.SaveMoney(id,money,map);

                            String type = "存";
                            Date date = new Date();
                            //SimpleDateFormat是一个以语言环境敏感的方式来格式化和分析日期的类。
                            //SimpleDateFormat允许你选择任何用户自定义日期时间格式来运行
                            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                            String time = ft.format(date);
                            String content = "+" + money;
                            Record record = new Record(id,type,time,content);
                            UserDao.AddRecord(id,record,map);
                            break;
                        case "3":
                            Scanner scanner4 = new Scanner(System.in);
                            System.out.println("请输入要取的金额");
                            double money2 = scanner4.nextDouble();
                            System.out.println(UserDao.WithdrawMoney(id, money2, map));
                            String type1 = "取";
                            Date date1 = new Date();
                            SimpleDateFormat ft1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                            String time1 = ft1.format(date1);
                            String content1 = "-" + money2;
                            Record record1 = new Record(id,type1,time1,content1);
                            UserDao.AddRecord(id,record1,map);
                            break;
                        case "4":
                            double money1 = UserDao.QueryMoney(id,map);
                            System.out.println("您的余额是：" + money1);
                            break;
                        case "5":
                            System.out.println("请拔出您的银行卡");
                            System.exit(0);
                        case "6":
                            ArrayList<Record> arrayList =  UserDao.QueryRecord(id,map);
                            //遍历
                            for(Record record2 : arrayList){
                                System.out.println(record2.toString());
                            }
                    }
                }
            }else {
                System.out.println("登录失败");
            }
        }
    }
}
